﻿using System.Xml.Linq;
using System;

namespace Lightray.Hattrick.ChppLib.EntityTypes
{
    public class Trophy
    {
        #region Properties
        public TrophyType TrophyType { get; private set; }
        public int SeasonNumber { get; private set; }
        public int LeagueLevel { get; private set; }
        public string LeagueLevelUnitName { get; private set; }
        public DateTime DateAwarded { get; private set; }
        public Uri ImageUri { get; private set; }
        #endregion

        private Trophy() { } 

        //TODO: Change to internal
        public static Trophy FromTeamXml(XElement trophyNode)
        {
            HattrickXmlReader reader = new HattrickXmlReader(trophyNode);
            return new Trophy()
            {
                // TODO: change to consts
                TrophyType = reader.ReadTrophyType("TrophyTypeId"),
                SeasonNumber = reader.ReadNumber("TrophySeason"),
                LeagueLevel = reader.ReadNumber("LeagueLevel"),
                LeagueLevelUnitName = reader.ReadString("LeagueLevelUnitName"),
                DateAwarded = reader.ReadDate("GainedDate"),
                ImageUri = reader.ReadUri("ImageUrl"),
            };
        }
        
        public override string ToString()
        {
            return string.Format("{0} Cup", TrophyType.ToString());
        }                           
    }
}

  
  